package domain.entities;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

/**
 * Protocolo entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "protocolo", catalog = "bms")
public class Protocolo implements java.io.Serializable {

	// Fields

	private String id;
	private LaboratorioCentral laboratorioCentral;
	private Integer eusu;
	private String title;
    private String name;
    private String inhouse;
    private String chronic;
	private Set<ProtocoloCompromisopais> protocoloCompromisopaises = new HashSet<ProtocoloCompromisopais>(
			0);
	private Collection<Droga> drogas = new ArrayList<Droga>(0);
    private Set<ProtocoloImportacion> protocoloImportaciones = new HashSet<ProtocoloImportacion>();

    // Constructors

	/** default constructor */
	public Protocolo() {
	}

	/** minimal constructor */
	public Protocolo(String id, LaboratorioCentral laboratorioCentral) {
		this.id = id;
		this.laboratorioCentral = laboratorioCentral;
	}

	/** full constructor */
	public Protocolo(String id, LaboratorioCentral laboratorioCentral,
			Integer eusu, String title,String name,
			Set<ProtocoloCompromisopais> protocoloCompromisopaises,
			Collection drogas) {
		this.id = id;
		this.laboratorioCentral = laboratorioCentral;
		this.eusu = eusu;
		this.title = title;
		this.protocoloCompromisopaises = protocoloCompromisopaises;
		this.drogas = drogas;
        this.name = name;
	}

	// Property accessors
	@Id
	@Column(name = "id", unique = true, nullable = false)
	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "LABORATORIO_CENTRALid2")
	public LaboratorioCentral getLaboratorioCentral() {
		return this.laboratorioCentral;
	}

	public void setLaboratorioCentral(LaboratorioCentral laboratorioCentral) {
		this.laboratorioCentral = laboratorioCentral;
	}

	@Column(name = "eusu")
	public Integer getEusu() {
		return this.eusu;
	}

	public void setEusu(Integer eusu) {
		this.eusu = eusu;
	}

	@Column(name = "title")
	public String getTitle() {
		return this.title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

    @Column(name = "protocolName")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "protocolo")
    @OrderBy("id.compromisopaisid")
    @LazyCollection(LazyCollectionOption.FALSE)
	public Set<ProtocoloCompromisopais> getProtocoloCompromisopaises() {
		return this.protocoloCompromisopaises;
	}

	public void setProtocoloCompromisopaises(
			Set<ProtocoloCompromisopais> protocoloCompromisopaises) {
		this.protocoloCompromisopaises = protocoloCompromisopaises;
	}

	@ManyToMany(cascade = CascadeType.ALL)
    @LazyCollection(LazyCollectionOption.FALSE)
	@JoinTable(name = "protocolo_droga", catalog = "bms", joinColumns = { @JoinColumn(name = "protocoloid", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "drogaid", nullable = false, updatable = false) })
	public Collection<Droga> getDrogas() {
		return this.drogas;
	}

	public void setDrogas(Collection<Droga> drogas) {
		this.drogas = drogas;
	}

    @Column(name = "inhouse")
    public String getInhouse() {
        return inhouse;
    }

    public void setInhouse(String inhouse) {
        this.inhouse = inhouse;
    }

    private TherapeuticArea therapeuticArea;

    @ManyToOne(cascade = CascadeType.ALL)
    public TherapeuticArea getTherapeuticArea() {
        return therapeuticArea;
    }

    public void setTherapeuticArea(TherapeuticArea therapeuticArea) {
        this.therapeuticArea = therapeuticArea;
    }

    private Specialty speciality;

    @ManyToOne()
    public Specialty getSpeciality() {
        return speciality;
    }

    public void setSpeciality(Specialty speciality) {
        this.speciality = speciality;
    }

    @OneToMany(cascade = CascadeType.ALL,mappedBy = "protocolo")
    @LazyCollection(LazyCollectionOption.FALSE)
    public Set<ProtocoloImportacion> getProtocoloImportaciones() {
        return this.protocoloImportaciones;
    }

    public void setProtocoloImportaciones(Set<ProtocoloImportacion> protocoloImportaciones) {
        this.protocoloImportaciones = protocoloImportaciones;
    }

    public boolean equals(Object obj) {
        Protocolo otro = (Protocolo)obj;
        if(otro == null || otro.id == null)
            return false;
        return this.id.equals(otro.id);
    }


    public void addProtocoloImportacion(ProtocoloImportacion pi) {
        this.protocoloImportaciones.add(pi);
    }

    @Column(name = "chronic")
    public String getChronic() {
        return chronic;
    }

    public void setChronic(String chronic) {
        this.chronic = chronic;
    }

}